$(function(){


    var wsServer = 'ws://192.168.33.10:8812';
    var websocket = new WebSocket(wsServer);
    websocket.onopen = function(evt){
        console.log('初始化');   
    }
    websocket.onmessage = function(evt){
        push(evt.data);
    }
    websocket.onclose = function(evt){
        console.log('关闭');
    }
    websocket.onerror = function(evt){
        console.log('错误');
    }


    function push(data)
    {
        var data = JSON.parse(data);
        var html = '<div class="comment">';
		html += '<span>'+data.user+'</span>：<span>'+data.content+'</span>'
        html += '</div>';
        $('#comments').append(html);
    }


    $('#discuss-box').keydown(function(event){
        if(event.keyCode == 13){
            var text = $(this).val();
            var url = 'http://192.168.33.10:8811/?s=index/chart/index';
            var data = {'content':text,'game_id':1};
            $.post(url,data,function(result){
                $('#discuss-box').val('');
            },'json');
        }
    })
})